package com.fudan.backend.dao;

import com.fudan.backend.handler.IdTypeHandler;
import com.fudan.backend.pojo.StoreParticipateInActivityRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StoreParticipateInActivityRequestDao {
    @Results(id = "storeParticipateInActivityRequestMap", value = {
            @Result(column = "store_participate_in_activity_request_id", property = "storeParticipateInActivityRequestId", typeHandler = IdTypeHandler.class),
            @Result(column = "activity_id", property = "activityId", typeHandler = IdTypeHandler.class),
            @Result(column = "store_id", property = "storeId", typeHandler = IdTypeHandler.class),
            @Result(column = "initiate_time", property = "initiateTime"),
            @Result(column = "process_time", property = "processTime"),
            @Result(column = "status", property = "status"),
            @Result(column = "info", property = "info"),
    })
    @Select("select * from t_store_participate_in_activity_request")
    List<StoreParticipateInActivityRequest> selectAllStoreParticipateInActivityRequest();

    @ResultMap("storeParticipateInActivityRequestMap")
    @Select("select * from t_store_participate_in_activity_request where store_participate_in_activity_request_id = #{storeParticipateInActivityRequestId}")
    StoreParticipateInActivityRequest selectStoreParticipateInActivityRequestById(String storeParticipateInActivityRequestId);

    @ResultMap("storeParticipateInActivityRequestMap")
    @Select("select * from t_store_participate_in_activity_request where store_id = #{storeId}")
    List<StoreParticipateInActivityRequest> selectAllStoreParticipateInActivityRequestByStoreId(String storeId);

    @ResultMap("storeParticipateInActivityRequestMap")
    @Select("select * from t_store_participate_in_activity_request where store_id = #{storeId} and status = 0")
    List<StoreParticipateInActivityRequest> selectAllUnprocessedStoreParticipateInActivityRequestByStoreId(String storeId);

    @Insert("insert into t_store_participate_in_activity_request values " +
            "(#{storeParticipateInActivityRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{activityId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{storeId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, #{initiateTime}, #{processTime}, " +
            "#{status}, #{info})")
    int insertStoreParticipateInActivityRequest(StoreParticipateInActivityRequest storeParticipateInActivityRequest);

    @Update("update t_store_participate_in_activity_request set " +
            "process_time = #{processTime}, status = #{status}, info = #{info} " +
            "where store_participate_in_activity_request_id = #{storeParticipateInActivityRequestId}")
    int updateStoreParticipateInActivityRequest(StoreParticipateInActivityRequest storeParticipateInActivityRequest);
}
